package com.bdzl.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.bdzl.base.controller.BaseController;
import com.bdzl.common.bean.BaseResponse;
import com.bdzl.request.AddAdmin;
import com.bdzl.request.AddCompany;
import com.bdzl.request.Login;
import com.bdzl.request.UpdAdmin;
import com.bdzl.request.UpdDis;
import com.bdzl.service.AdminService;

@RestController
@RequestMapping("/v1")
public class AdminController extends BaseController {

	@Resource(name = "adminService")
	private AdminService adminService;

	/**
	 * 后台登陆
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public @ResponseBody BaseResponse login(Login login) throws Exception {
		BaseResponse baseResponse = adminService.login(login);
		return baseResponse;
	}

	/**
	 * 获取管理员列表
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/admins/getAllAdmins", method = RequestMethod.GET)
	public @ResponseBody BaseResponse allAdmin() throws Exception {
		BaseResponse baseResponse = adminService.allAdmin();
		return baseResponse;
	}

	/**
	 * 添加管理员
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/admins/newAdmin", method = RequestMethod.POST)
	public @ResponseBody BaseResponse addAdmin(@RequestBody AddAdmin addAdmin) throws Exception {
		BaseResponse baseResponse = adminService.addadmin(addAdmin);

		return baseResponse;
	}

	/**
	 * 删除管理员
	 * 
	 * @param adminId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/admins/deleteAdmin/{adminId}", method = RequestMethod.DELETE)
	public @ResponseBody BaseResponse deladmin(@PathVariable("adminId") Integer adminId) throws Exception {
		BaseResponse baseResponse = adminService.deladmin(adminId);

		return baseResponse;
	}

	/**
	 * 修改管理员信息
	 * 
	 * @param adminId
	 * @param updAdmin
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/admins/modifyAdmin/{adminId}", method = RequestMethod.PUT)
	public @ResponseBody BaseResponse updadmin(@PathVariable("adminId") Integer adminId, @RequestBody UpdAdmin updAdmin)
			throws Exception {
		BaseResponse baseResponse = adminService.updadmin(adminId, updAdmin);

		return baseResponse;
	}

	/**
	 * 获取意见列表
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/feedbacks/getAllfeedbacks", method = RequestMethod.GET)
	public @ResponseBody BaseResponse allfb(@RequestParam("pageIndex") Integer pageIndex,
			@RequestParam("pageSize") Integer pageSize) throws Exception {
		BaseResponse baseResponse = adminService.allfb(pageIndex, pageSize);

		return baseResponse;
	}

	/**
	 * 删除意见
	 * 
	 * @param feedbackId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/feedbacks/deletefeedback/{feedbackId}", method = RequestMethod.DELETE)
	public @ResponseBody BaseResponse delfb(@PathVariable("feedbackId") Integer feedbackId) throws Exception {
		BaseResponse baseResponse = adminService.delfb(feedbackId);

		return baseResponse;
	}

	/**
	 * 意见已读
	 * 
	 * @param feedbackId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/feedbacks/readFeedback/{feedbackId}", method = RequestMethod.PUT)
	public @ResponseBody BaseResponse updafb(@PathVariable("feedbackId") Integer feedbackId) throws Exception {
		BaseResponse baseResponse = adminService.updafb(feedbackId);

		return baseResponse;
	}

	/**
	 * 获取公司列表
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/companies/getAllcompanies", method = RequestMethod.GET)
	public @ResponseBody BaseResponse allcom() throws Exception {
		BaseResponse baseResponse = adminService.allcom();

		return baseResponse;
	}

	/**
	 * 新增公司
	 * 
	 * @param addCompany
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/companies/newCompany", method = RequestMethod.POST)
	public @ResponseBody BaseResponse addcm(@RequestBody AddCompany addCompany) throws Exception {
		BaseResponse baseResponse = adminService.addcm(addCompany);

		return baseResponse;
	}

	/**
	 * 修改公司
	 * 
	 * @param companyId
	 * @param addCompany
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/companies/modifyCompany/{companyId}", method = RequestMethod.PUT)
	public @ResponseBody BaseResponse updacm(@PathVariable("companyId") Integer companyId,
			@RequestBody AddCompany addCompany) throws Exception {
		BaseResponse baseResponse = adminService.updacm(companyId, addCompany);

		return baseResponse;
	}

	/**
	 * 删除公司
	 * 
	 * @param companyId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/companies/deleteCompany/{companyId}", method = RequestMethod.DELETE)
	public @ResponseBody BaseResponse delcm(@PathVariable("companyId") Integer companyId) throws Exception {
		BaseResponse baseResponse = adminService.delcm(companyId);

		return baseResponse;
	}

	/**
	 * 获取病种列表
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/disease/getAlldiseases", method = RequestMethod.GET)
	public @ResponseBody BaseResponse alldis() throws Exception {
		BaseResponse baseResponse = adminService.alldis();

		return baseResponse;
	}

	/**
	 * 更新病种列表
	 * 
	 * @param updDis
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/disease/modifyAlldiseases", method = RequestMethod.PUT)
	public @ResponseBody BaseResponse updatedis(@RequestBody UpdDis updDis) throws Exception {
		BaseResponse baseResponse = adminService.updatedis(updDis);

		return baseResponse;
	}

}
